﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FileMonitor.Configuration.Tool.Controls.Prototype;

namespace FileMonitor.Configuration.Tool.Controls
{
    public partial class KeyValueEditor : UserControl
    {
        private Mode _mode;

        public Mode Mode
        {
            get { return this._mode; }
            set 
            {
                if (value == Mode.Edit)
                {
                    this.txtKey.ReadOnly = true;
                    this.btnDelete.Visible = true;
                }
                this._mode = value; 
            }
        }

        public KeyValueEditor()
        {
            InitializeComponent();
        }

        public string KeyDispalyName
        {
            get { return this.lblKey.Text; }
            set { this.lblKey.Text = value; }
        }

        public string ValueDisplayName
        {
            get { return this.lblValue.Text; }
            set { this.lblValue.Text = value; }
        }

        public delegate void SaveHandler(object sender, KeyValueSaveArgs args);
        public delegate void DeleteHandler(object sender, KeyValueSaveArgs args);

        public event SaveHandler Save;
        public event DeleteHandler Delete;


        private void OnSave(object sender, KeyValueSaveArgs args)
        {
            if(Save!=null)
            {
                Save(this,args);
            }
        }

        private void OnDelete(object sender, KeyValueSaveArgs args)
        {
            if (Delete != null)
            {
                Delete(this, args);
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            OnSave(this, new KeyValueSaveArgs(this.txtKey.Text, this.txtValue.Text));
        }

        public void BindData(string key, string value)
        {
            this.txtKey.Text = key;
            this.txtValue.Text = value;
        }

        private void Delete_Click(object sender, EventArgs e)
        {
            OnDelete(this, new KeyValueSaveArgs(this.txtKey.Text, this.txtValue.Text));
        }
    }

   
}
